package com.czk.doc;

import com.czk.util.ClientUtil;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;

import java.io.IOException;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/6/13 14:11
 */
public class UpdateDoc {
    public static void main(String[] args) throws IOException {
        // 拿到客户端
        RestHighLevelClient highLevelClient = ClientUtil.getHighLevelClient();
        // 修改数据
        UpdateRequest updateRequest = new UpdateRequest();
        // 设置修改的文档和索引
        updateRequest.index("user").id("1001");
        updateRequest.doc(XContentType.JSON, "sex", "女");
        //
        highLevelClient.update(updateRequest, RequestOptions.DEFAULT);
        highLevelClient.close();
    }
}
